﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using MethodIT.Helper;
using MyGeneration.dOOdads;

using Hr20.DAL;
using Hr20.BLL;
using Hr20.ProcessFlow;

namespace Appraisal.Web
{
    public partial class Login1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            btnKeyLogin.Attributes.Add("onclick", "GetGUID();");
            txtGUID.Style.Add("display", "none");
            //DBController.GetInstance().Login("admin");
            //FormsAuthentication.RedirectFromLoginPage("admin", false);
        }
        protected void btnLogin_Click(object sender, System.EventArgs e)
        {
            string sUserName = txtUserName.Value;
            string sPassword = txtPassword.Value;

            if (DBController.GetInstance().Authenticate(sUserName, sPassword))
            {
                DBController.GetInstance().Login(sUserName);
                Response.Redirect("Default.aspx");
            }
            else
            {
                HelperMessage.MessageUrl("用户名或密码错误!","Login.aspx");
//                return
            }
        }

        protected void btnKeyLogin_Click(object sender, EventArgs e)
        {
            string sGUID = (txtGUID.Text == "") ? "Faile" : txtGUID.Text;
            AP_User u = new AP_User();
            u.Where.Status.Value = true;
            u.Where.KeyCode.Value = sGUID;
            if (u.Query.Load())
            {
                DBController.GetInstance().Login(u.User_ID);
                Response.Redirect("Default.aspx");
            }
            else
            {
                HelperMessage.Message("请重新插入USBKEY,并检查控件是否安装!");
                return;
            }
        }
    }
}
